import { Component, Vue, Inject } from 'vue-property-decorator';

import { IContentInfo } from '@/shared/model/content-info.model';
import ContentInfoService from './content-info.service';

@Component
export default class ContentInfoDetails extends Vue {
  @Inject('contentInfoService') private contentInfoService: () => ContentInfoService;
  public contentInfo: IContentInfo = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.contentInfoId) {
        vm.retrieveContentInfo(to.params.contentInfoId);
      }
    });
  }

  public retrieveContentInfo(contentInfoId) {
    this.contentInfoService()
      .find(contentInfoId)
      .then(res => {
        this.contentInfo = res;
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
